﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;

namespace PizzaWic.admin
{
    /// <summary>
    /// permet de gérer les cuisiniers (affichage et modification)
    /// </summary>
    public partial class CookerManagement : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //on affiche la liste des cuisiniers
                SqlAccess sql = new SqlAccess();
                DataSet dataSet = new DataSet();
                dataSet = sql.getAllCooker();

                MonRepeater.DataSource = dataSet;
                MonRepeater.DataBind();
            }
        }

        /// <summary>
        /// action sur le repeater
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void MonRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            SqlAccess sql = new SqlAccess();
            //edition d'un cuinier
            if (e.CommandName == "edit_cooker")
            {
                Object[] data = new Object[6];
                data[0] = e.CommandArgument;
                //mise à jour des valeurs des champs
                data[1] = ((TextBox)e.Item.FindControl("editName")).Text;
                data[2] = ((TextBox)e.Item.FindControl("editsurname")).Text;
                data[3] = ((TextBox)e.Item.FindControl("editLogin")).Text;
                data[4] = ((TextBox)e.Item.FindControl("editPassword")).Text;
                sql.setCooker(data);
            }

            //suppresion d'un cuisinier
            else if (e.CommandName == "delete_cooker")
            {
                Object[] param = new Object[1];
                param[0] = e.CommandArgument;
                sql.delCooker(param);
            }

            //mise à jour de la vue
            DataSet dataSet = new DataSet();
            dataSet = sql.getAllCooker();
            MonRepeater.DataSource = dataSet;
            MonRepeater.DataBind();
        }

    }
}